﻿namespace Furesoft.WPF.Game
{
    using System;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Navigation;

    public class ScreenManager
    {
        #region Static Fields

        private static readonly List<Page> screens = new List<Page>();

        private static Frame frame;

        private static Window window;

        #endregion

        #region Public Properties

        public static Page CurrentScreen { get; internal set; }

        #endregion

        public static event EventHandler ScreenChanged;

        private static void OnScreenChanged()
        {
            EventHandler handler = ScreenChanged;
            if (handler != null)
            {
                handler(CurrentScreen, EventArgs.Empty);
            }
        }

        #region Public Methods and Operators

        public static void ChangeScreen(Page screen)
        {
            if (screens.Contains(screen))
            {
                CurrentScreen = screen;
            }
            else
            {
                screens.Add(screen);
                CurrentScreen = screen;
            }

            frame.Navigate(screen);

            OnScreenChanged();
        }

        public static void Initialize(Window win)
        {
            window = win;

            frame = new Frame();
            frame.Name = "GameDisplay";
            frame.NavigationUIVisibility = NavigationUIVisibility.Hidden;

            window.Content = frame;
        }

        #endregion
    }
}